﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;   //   for Texture2D
using Microsoft.Xna.Framework;  //  for Vector2

namespace zombieArena
{
    class Bullet
    {
        public Vector2 position;
        public Vector2 velocity { get; set; }
        public Texture2D bulletTexture { get; set; }
        public Vector2 midPoint { get; set; }
        public Vector2 blastMidPoint { get; set; }
        // 0, regular bullet
        // 1, infinite durability bullet
        // 2, explosive
        public int state { get; set; }
        public float hitRadius { get; set; }
        public float lifeTime { get; set; }
        public float maxLifeTime { get; set; }
        // explosions!
        public float blastRadius { get; set; }
        public float blastMaxTime { get; set; }
        public Texture2D blastTexture { get; set; }
        public float rotate = 0f;
        public float scale = 1f;

        //optimize
        Vector2 bulletscreenpos;
        //private Vector2 drawOrigin = new Vector2(8f, 8f);

        public Bullet()
        {
        }

        public Bullet(Vector2 p, Vector2 v, Texture2D bt)
        {
            position = p;
            velocity = v;
            bulletTexture = bt;
            state = 0;
            hitRadius = 40f;
            lifeTime = 0f;
            maxLifeTime = 10000f;
            midPoint = new Vector2(8f, 8f);

            // optimize
            this.bulletscreenpos = position;
        }

        public Bullet(Vector2 position, Vector2 velocity, Texture2D bulletTexture, int state, float hitRadius, float blastRadius, float maxLifeTime, float blastMaxTime, Vector2 midPoint)
        {
            this.position = position;
            this.velocity = velocity;
            this.bulletTexture = bulletTexture;
            this.state = state;
            this.hitRadius = hitRadius;
            this.blastRadius = blastRadius;
            this.maxLifeTime = maxLifeTime;
            this.blastMaxTime = blastMaxTime;
            this.midPoint = midPoint;

            // optimize
            this.bulletscreenpos = position;
        }

        public Bullet(Vector2 position, Vector2 velocity, Texture2D bulletTexture, int state, float hitRadius, Texture2D blastTexture, float blastRadius, float maxLifeTime, float blastMaxTime, Vector2 midPoint, Vector2 midPoint2)
        {
            this.position = position;
            this.velocity = velocity;
            this.bulletTexture = bulletTexture;
            this.blastTexture = blastTexture;
            this.state = state;
            this.hitRadius = hitRadius;
            this.blastRadius = blastRadius;
            this.maxLifeTime = maxLifeTime;
            this.blastMaxTime = blastMaxTime;
            this.midPoint = midPoint;
            this.blastMidPoint = midPoint2;

            // optimize
            this.bulletscreenpos = position;
        }

        public void move(ref GameTime gameTime)
        {
            position.X += velocity.X;
            position.Y += velocity.Y;
            //position = position + velocity;
            lifeTime += gameTime.ElapsedGameTime.Milliseconds;
        }

        public void Draw(ref SpriteBatch spriteBatch, ref Rectangle viewPort)
        {
            //Vector2 bulletscreenpos = position - new Vector2(viewPort.X, viewPort.Y);
            //Vector2 bulletscreenpos = -new Vector2(viewPort.X, viewPort.Y);
            //Vector2 bulletscreenpos = new Vector2(position.X - viewPort.X, position.Y - viewPort.Y);
            // optimize
            bulletscreenpos.X = position.X - viewPort.X;
            bulletscreenpos.Y = position.Y - viewPort.Y;
            spriteBatch.Draw(bulletTexture, bulletscreenpos, null, Color.White, rotate, midPoint, scale, SpriteEffects.None, 0);
        }
    }
}
